import request from "./request.js"
export default {
	getToken() {
		let token = uni.getStorageSync('token')
		if (token) {
			return token
		} else {
			uni.navigateTo({
				url: '/pages/logIn/logIn',
			});
		}
	},
	commonUpload(data) {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: 'https://mkb.xjie.vip/api/common/upload',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'token': this.getToken()
				},
				name: 'file',
				filePath: data.path,
				file: data.file,
				success: (res) => {
					resolve(JSON.parse(res.data).data.url)
				},
				fail: (err) => {
					console.log('请求失败', err)
				}
			});
		})
	},
	async commonUploads(datas) {
		let arr = []
		for (let i = 0; i < datas.length; i++) {
			arr.push(await this.commonUpload(datas[i]))
		}
		return String(arr)
	},
}
